package edu.amm.fanal.api;

import edu.amm.api.Bounds;

/**
 * Тригонометрическая система координат, образованная синусами.
 * 
 * @author Иванов Илья
 * @since 2013-05-12
 *
 */
public class SineCoordinates extends Coordinates {
	
	protected SineCoordinates(Bounds bounds) {
		super(bounds);
	}
	
	public String getName() {
		return getCoordinatesName();
	}
	
	protected Function[] coordinates(int count) {
		final double a = getLeftBound();
		final double b = getRightBound();
		
		Function[] coordinates = new Function[count];
		for (int i = 0; i < coordinates.length; i++) {
			final int k = i + 1;
			
			coordinates[i] = new Function(BoundaryProblem.SOLUTION_DIM) {
				
				private double alpha = k * Math.PI / (b - a);
				
				private Function firstDerivative = new Function(getDim()) {
					
					private Function secondDerivative = new Function(getDim()) {
						
						private double alpha2 = alpha * alpha;
						
						protected double getValue(double... x) {
							return - alpha2 * Math.sin(alpha * (x[0] - a));
						}
					};
					
					protected double getValue(double... x) {
						return alpha * Math.cos(alpha * (x[0] - a));
					}
					
					protected Function getDerivative(int variableNumber) {
						return secondDerivative;
					}
				};
				
				protected double getValue(double... x) {
					return Math.sin(alpha * (x[0] - a));
				}
				
				protected Function getDerivative(int variableNumber) {
					return firstDerivative;
				}
			};
		}
		
		return coordinates;
	}
	
	public static String getCoordinatesName() {
		return "Cинусы";
	}
}